<style type="text/css">
    .action-cell {
        margin-bottom: 20px;
    }

    .search-block {
        display: flex;
        margin-bottom: 10px;
    }

    .input-search {
        margin-right: 10px;
    }
</style>
<template>
    <div>
        <div class="action-cell">
            <!--<div class="search-block">-->
            <!--<Input v-model="value" class="input-search" placeholder="根据时间查询" style="width: 200px"></Input>-->
            <!--<Input v-model="value" class="input-search" placeholder="根据编队查找" style="width: 200px"></Input>-->
            <!--<Input v-model="value" class="input-search" placeholder="根据时间查找" style="width: 200px"></Input>-->
            <!--<Input v-model="value" class="input-search" placeholder="根据证件号查找" style="width: 200px"></Input>-->
            <!--<Button type="ghost" icon="ios-search">搜索</Button>-->
            <!--</div>-->
            <Button type="error" @click="jumpPage('','RepairAdd')">添加</Button>
        </div>
        <Table :context="self" :data="tableData" :columns="tableColumns" stripe border></Table>
        <div style="margin: 10px;overflow: hidden">
            <div style="float: right;">
                <Page :total="total" size="large" show-total :current="current" show-elevator show-sizer
                      @on-change="changePage"></Page>
            </div>
        </div>
    </div>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';

    export default {
        data() {
            return {
                self: this,
                tableData: [],
                total: 0,
                current: 1,
                visitorId: '',
                tableColumns: [
                    {
                        title: '报修人',
                        key: 'People',
                        align: 'center',
                    },
                    {
                        title: '报修人电话',
                        key: 'Contact',
                        align: 'center',
                    },
                    {
                        title: '报修详情',
                        key: 'Requestcontent',
                        align: 'center',
                    },
                    // {
                    //     title: '维修人',
                    //     key: 'repairpeople',
                    //     align: 'center',
                    //     render: function (h, params) {
                    //         return h('span', params.row.repairpeople ? params.row.repairpeople : '暂无')
                    //     }
                    // },
                    //
                    // {
                    //     title: '维修人电话',
                    //     key: 'repaircontact',
                    //     align: 'center',
                    //     render: function (h, params) {
                    //         return h('span', params.row.repaircontact ? params.row.repaircontact : '暂无')
                    //     }
                    // },
                    {
                        title: '报修时间',
                        key: 'Opdate',
                        align: 'center',
                    },
                    {
                        title: '状态',
                        key: 'State',
                        align: 'center',
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: '',
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    style: {
                                        'margin-right': '10px',
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.row.Id, params.row.Forpeopleid);
                                        }
                                    }
                                }, '删除'),
                                // h('Button', {
                                //     props: {
                                //         type: 'text',
                                //         size: 'small'
                                //     },
                                //     style: {
                                //
                                //         'margin-right': '10px',
                                //     },
                                //     on: {
                                //         click: () => {
                                //             let that = this;
                                //             this.jumpPage(params.row.id, 'RepairEdit1', that.current, params.index);
                                //         }
                                //     }
                                // }, '修改信息'),
                                // h('Button', {
                                //     props: {
                                //         type: 'primary',
                                //         size: 'small'
                                //     },
                                //     style: {
                                //
                                //         'margin-right': '10px',
                                //     },
                                //     on: {
                                //         click: () => {
                                //             let that = this;
                                //             this.jumpPage(params.row.id, 'RepairEdit1', that.current, params.index);
                                //         }
                                //     }
                                // }, '修改信息'),
                                // h('Button', {
                                //     props: {
                                //         type: 'primary',
                                //         size: 'small'
                                //     },
                                //     style: {
                                //         'margin-right': '10px',
                                //     },
                                //     on: {
                                //         click: () => {
                                //             let that = this;
                                //
                                //             this.jumpPage(params.row.id, 'RepairEdit2', that.current, params.index);
                                //         }
                                //     }
                                // }, '派工'),
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {

                                        'margin-right': '10px',
                                    },
                                    on: {
                                        click: () => {
                                            this.editOrder(params.row.Id, '结单')
                                        }
                                    }
                                }, '结单'),
                            ])
                        }
                    }
                ]
            }
        },
        mounted() {
            this.mockTableData();
            this.visitorId = this.$route.query.id;
        },
        methods: {
            //跳转
            jumpPage: function (id, url, curPage, index) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    console.log('curPage:', curPage);
                    if (curPage && curPage > 0) {
                        route = {
                            path: url,
                            query: {
                                id: id,
                                curPage: curPage,
                                index: index
                            }
                        }
                    } else {
                        route = {
                            path: url,
                            query: {
                                id: id,
                            }
                        }
                    }

                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            mockTableData() {
                let that = this;

                let para = {
                    // peopleId: '87415a1b-922e-4a94-83c6-8f16c74ab0fb',
                    peopleId: '5c23dff3-5a7a-49ec-a833-4a48b31b2221',
                    curPage: this.current,
                    pageSize: 10,
                };
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.MyRepairList, para, function (res) {
                    that.$Loading.finish();
                    that.total = res.Msg.TotalCount;
                    that.current = res.Msg.CurrentPage;
                    that.tableData = res.Msg.Arrays;

                    console.log('tableData:', res)
                });

            },
            remove(id, id2) {
                let that = this;
                this.$Modal.confirm({
                    title: '用户信息',
                    content: `是否删除该记录`,
                    onOk: function () {
                        this.$Loading.start();
                        let para = {
                            id: id,
                            peopleId: id2,
                        };
                        let params = that.$qs.stringify(para);

                        apiUtil.post(that, apiUtil.urls.DelRepairRequest, params, function (res) {
                            that.mockTableData();
                        });
                    }
                })
            },
            editOrder: function (id, state) {
                let that = this;
                this.$Modal.confirm({
                    title: '提示',
                    content: '确定' + state + '此保修项吗',
                    onOk: function () {
                        this.$Loading.start();
                            let para = {
                                id: id,
                                peopleId: '87415a1b-922e-4a94-83c6-8f16c74ab0fb'
                            };

                        let params = that.$qs.stringify(para);
                        apiUtil.post(that, apiUtil.urls.FinishRepair, para, function (res) {
                            that.mockTableData();
                        });
                    }
                })
            },
            changePage(row) {
                // 这里直接更改了模拟的数据，真实使用场景应该从服务端获取数据
                console.log("row", row);
                this.current = row;
                this.mockTableData();
            }
        },
    }
</script>